/**
 * 
 */
package net.fdukedom.epicurus.domain.entity;

/**
 * Implements activation entity.
 *
 * @author Sergey Vishnyakov
 */
public final class Activation {

    
    /**
     * User's id.
     */
    private int userId = 0;
    
    /**
     * Activation code.
     */
    private String code = null;

    /**
     * User.
     */
    private User user = null;
    
    /**
     * Returns user.
     *
     * @return the user
     */
    public User getUser() {
        return user;
    }

    /**
     * Sets user.
     *
     * @param user the user to set
     */
    public void setUser(User user) {
        this.user = user;
    }

    /**
     * Default constructor. NB! Required by hibernate.     
     */
    public Activation() {
    }
    
    /**
     * General constructor. Sets all required data.
     *
     * @param user user
     * @param code code
     */
    public Activation(User user, String code) {
        this.user = user;
        this.code = code;        
    }

    /**
     * Returns activation code.
     *
     * @return the code
     */
    public String getCode() {
        return code;
    }

    /**
     * Sets activation code.
     *
     * @param code the code to set
     */
    public void setCode(String code) {
        this.code = code;
    }

    /**
     * Returns userId.
     *
     * @return the userId
     */
    public int getUserId() {
        return userId;
    }

    /**
     * Sets userId.
     * 
     * @param userId the userId to set
     */
    public void setUserId(int userId) {
        this.userId = userId;
    }

    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        final Activation that = (Activation) o;

        if (userId != that.userId) return false;
        if (!code.equals(that.code)) return false;

        return true;
    }

    public int hashCode() {
        int result;
        result = userId;
        result = 29 * result + code.hashCode();
        return result;
    }

    public String toString() {
        StringBuilder text = new StringBuilder();
        text.append("{userId: ");
        text.append(userId);
        text.append(", activation code: ");
        text.append(code);
        text.append("}");
        return text.toString();
    }
}
